<?php
namespace Admin\Controller;
use Admin\Controller;
/**
 * 单页管理
 */
class ProductController extends BaseController
{
    public function index(){
        $file = M('pro_dis_single')->order('id desc')->limit(0,3)->select();
        foreach ($file as $v){
            $imgArr[] = $v;
        }
//        var_dump($imgArr);
        $this->assign('imgArr',$imgArr);
        $this->display();
    }

    public function  product_upload(){
        $upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize = 3145728 ;// 设置附件上传大小
        $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型

        // 上传文件01
        $info = $upload->upload();
        if(!$info) {// 上传错误提示错误信息
            $this->error($upload->getError());
        }else{// 上传成功
            if (!$info['photo1']||!$info['photo2']||!$info['photo3']){
                $this->error('不支持单张图片上传,请三张一起上传!');
            }
            $data = array(
                '0' => array(
                    'filename' => $info['photo1']['savename'],
                    'fileurl' => $info['photo1']['savepath'],
                    'content' => $_POST['content1'],
                    'pid' => 1,
                ),
                '1' => array(
                    'filename' => $info['photo2']['savename'],
                    'fileurl' => $info['photo2']['savepath'],
                    'content' => $_POST['content2'],
                    'pid' => 2,
                ),
                '2' => array(
                    'filename' => $info['photo3']['savename'],
                    'fileurl' => $info['photo3']['savepath'],
                    'content' => $_POST['content2'],
                    'pid' => 3,
                ),
            );
            if ($pd = M('pro_dis_single')->addAll($data)){
                $this->success('上传成功！');
            }
        }
    }
}
?>